package yf.mall.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import yf.mall.dao.AddressDao;
import yf.mall.entity.AddressEntity;
import yf.mall.service.AddressService;
import com.yf.service.impl.BaseServiceImpl;
import org.springframework.transaction.annotation.Transactional;

/**
 * 地址Service实现类
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Mon Aug 26 16:40:35 CST 2019
 */
@Service
public class AddressServiceImpl extends BaseServiceImpl<AddressEntity> implements AddressService {

    private AddressDao addressDao;


    @Autowired
    public void setDao(AddressDao addressDao) {
        this.addressDao = addressDao;
        super.setBaseDao(addressDao);
    }



    /**内部方法**/


    /**外部方法实现**/

    @Override
    public List<AddressEntity> findByUserId(Long userId) {
        Map params = new HashMap();
        params.put("userId",userId);
        params.put("order","id desc");
        return addressDao.queryList(params);
    }

    @Override
   @Transactional(rollbackFor = Exception.class)
    public AddressEntity merge(AddressEntity addressEntity) {
        if(addressEntity.getId()==null){
            addressDao.save(addressEntity);
        }else {
            addressDao.update(addressEntity);
        }
        return addressEntity;
    }
}
